package com.masterclient.app.businessmodule.homemodule.view.adapter.liveone;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.GlideUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.commonbean.banner.BannerNewItemBean;
import com.masterclient.app.R;
import com.masterclient.app.utils.CommonUtil;

import java.util.List;

import static com.eoner.baselibrary.utils.ScreenUtils.dp2px;

public class HomePageLiveOneAdapter extends BaseQuickAdapter<BannerNewItemBean, BaseViewHolder> {

    public HomePageLiveOneAdapter(int layoutResId, @Nullable List<BannerNewItemBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BannerNewItemBean shTemporary) {

        ImageView imageView = helper.getView(R.id.image);
        int width = ScreenUtils.getScreenWidth() - dp2px(30) ;
        int height = width * 85 /343;
        if (!TextUtils.isEmpty(shTemporary.getWidth()) && !TextUtils.isEmpty(shTemporary.getHeight())){
            height = width * Integer.parseInt(shTemporary.getHeight()) /Integer.parseInt(shTemporary.getWidth());
        }
        GlideUtil.displayImage(mContext,shTemporary.getImage(),imageView);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(new ViewGroup.LayoutParams(width, height));
        imageView.setLayoutParams(params);
        imageView.setOnClickListener(v->{
            CommonUtil.goNewAnyWhere(mContext,shTemporary.getTarget_platform(),shTemporary.getTarget_message(), shTemporary.getTarget(), shTemporary.getTarget_id(), shTemporary.getImage(), shTemporary.getS_ad_name(), shTemporary.getS_ad_name());
        });
    }
}
